// 多源最短路径 
#include<iostream>
#include<cstring>
#include<queue>
// #define ONLINE_GUDGE
using namespace std;
using PII = pair<int, int>;
const int N = 810, M = 3010, INF = 0x3f3f3f3f;

int n, p, m;
int cow[N];
int e[M], ne[M], h[N], w[M], idx;
bool st[N]; // 是否从当前点找到最短路径
int dist[N];

void AddEdge(int a, int b, int c)
{
    e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx ++ ;
}

// 做法1：堆优化dijkstra 从点出发 适合稠密图
int dijkstra(int x)
{
    memset(st, 0, sizeof st);
    memset(dist, INF, sizeof dist);

     dist[x] = 0;
    priority_queue <PII,vector <PII>,greater <PII>> heap;
    heap.push({0, x});
    while(heap.size())
    {
        int u = heap.top().second; heap.pop();
        if(st[u]) continue;
        st[u] = true;
        for(int E = h[u]; ~E; E = ne[E]){
            int v = e[E];
            if(dist[v] > dist[u] + w[E]){
                dist[v] = dist[u] + w[E];
                heap.push({dist[v], v});
            }
        }
    }

    int ans = 0;
    for (int i = 1;i <= n;i++) {
        if (dist[cow[i]] == INF) return INF;
        ans += dist[cow[i]];
    }
    return ans;

}

// 做法2：spfa 从边出发 适合稀疏图

int spfa(int x)
{
    memset(st, 0, sizeof st);
    memset(dist, INF, sizeof dist);

    dist[x] = 0;
    queue<int> q;
    q.push(x);
    st[x] = true;

    while(q.size())
    {
        auto u = q.front();q.pop();

        st[u] = false;

        for(int i = h[u]; ~i; i = ne[i])
        {
            int v = e[i];
            if(dist[v] > dist[u] + w[i]){ // 这个权值更新终点，对整体结果有影响
                dist[v] = dist[u] + w[i];
                if(!st[v])
                {
                    st[v] = true; // 更新为最短路径
                    q.push(v);
                }
            }
        }
    }

    int ans = 0;
    for (int i = 1;i <= n;i++) {
        if (dist[cow[i]] == INF) return INF;
        ans += dist[cow[i]];
    }
    return ans;

}

int main()
{
    #ifdef ONLINE_JUDGE

    #else
    freopen("./in.txt","r",stdin);
    #endif
    ios::sync_with_stdio(false);   
	cin.tie(0);

    memset(h, -1, sizeof h);
    cin >> n >> p >> m;
    for(int i = 1; i <= n; i++) cin >> cow[i];
    while(m--)
    {
        int a, b, c; cin >> a >> b >> c;
        AddEdge(a, b, c); AddEdge(b, a, c);
    }

    int ans = INF;
    // for(int i = 1; i <= p; i++) ans = min(ans, dijkstra(i));
    for(int i = 1; i <= p; i++) ans = min(ans, spfa(i));
    cout << ans << endl;
    return 0;
}